<template>
  <view class="content">
	 <view style="display: flex;justify-content: center;align-items: center;height: 400px">
		 <image style="width: 250px; height: 250px; background-color: #eeeeee;" :src="imgUrl">
		 </image>
	 </view>
	 <view style="display: block;width: 50%;margin:0 auto;">
		 <button @click="scanBarcode">扫描二维码</button>
	 </view>
    <!-- <h3 >请扫描二维码查看消息列表</h3> -->
  </view>
</template>

<script>
import io from 'socket.io-client/dist/socket.io.js';
export default {
  data() {
    return {
        barcode: '',
      socket: null,
	  imgUrl: require('../../static/btnImg.png'),
      messages: [],
    };
  },
  methods: {
    scanBarcode() {
        let that = this;
        console.log('sssdff')
   
        uni.scanCode({
            success: function(res) {
                console.log('条码类型：' + res.scanType);
                console.log('条码内容：' + res.result);
                that.barcode = res.result;
                uni.showToast({
                    title: '扫码成功！',
                    duration: 2000
                });
				console.log(11111, res.result)
				const paramsStr = JSON.parse(res.result);
				uni.setStorage({
				  key: 'barcode',
				  data: paramsStr,
				  success: function () {
				    console.log('数据缓存成功');
				  }
				});
                setTimeout(function() {
                    that.navigateToPage();
                }, 2000);
            }
        });
    },
    navigateToPage() {

		uni.navigateTo({
		    url: '/pages/index/index'
		});
        // 将对象转换为 JSON 字符串并进行编码
        // 使用 uni.navigateTo 跳转到新页面，并传递参数
       
    }
  }
};
</script>

<style scoped>
/* 添加你的样式 */
.content {

  height: 95vh;
  width: 100vw;
}

.container {
  width: 100%;
  height: 100%;
  background-color: gold;
}

button {
  padding: 5px 40px;
  background-color: transparent;
  color: #007AFF;
  font-weight: 600;
  font-size: 15px;
  width:100%;
  border:3px solid #007AFF;
  border-radius: 5px;
  display: block;
}
</style>
